home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
uwsrc.arc
/
WINSUBR.C
< prev
Wrap
C/C++ Source or Header
|
1989-04-29
|
29KB
|
1,259 lines
/* subroutines for multi-window terminal emulation
*/
#include <obdefs.h>
#include <gemdefs.h>
#include <osbind.h>
#include <stdio.h>
#include "wind.h"
#include "windefs.h"
extern int handle;
/* variables used by various routines
*/
long dummy; /* dummy return variable */
extern int outwind, outport; /* window selection */
extern int scr_x, scr_y; /* size of the screen */
extern int scr_w, scr_h;
extern int fast; /* flag for fast open/close */
extern int overstrike;
extern int sliders; /* flag for sliders on new windows */
extern int titles; /* flag for title bars on new windows */
int tmp; /* temporary for anything... */
extern char alert[300]; /* used for alerts */
extern FNT *curfont; /* current font */
extern MFDB screen_mf; /* screen descriptor */
extern int mouse; /* for mouse on/off */
extern int audibell; /* What happens on BEL? */
extern int visibell;
extern int toponbel;
struct wi_str w[MAX_WIND];
/* the program code...
*/
char *getmem(size)
register long size;
{
char *got;
got = (char *) Malloc(size);
#ifdef DEBUG
printf("alloc returned %lx of %ld size\n", got, size);
#endif
if (got == NULL)
{
sprintf(alert, "[1][Could not get %ld bytes][Ok]", size);
form_alert(1, alert);
} else
{
bzero(got, size);
}
return got;
}
bzero(ptr, size)
register char *ptr;
register long size;
{
while (size--)
*ptr++ = 0;
}
/* find_port maps from window handles to UW port identifiers
*/
find_port(wnd)
{
return w[wnd].port;
}
/* find_wind maps from port ids to window handles
*/
find_wind(port)
{
int i;
for (i=1; i<MAX_WIND; i++)
if (w[i].port == port) return i;
return 0;
}
/* w_open opens a window with the supplied name and port and returns a port
* number. If port was zero, a free port is chosen.
*/
w_open(port, name, xsiz, ysiz)
char *name;
{
register struct wi_str *wp;
int wdes;
int i, cnt, wtyp;
int tmp_x, tmp_y, tmp_w, tmp_h;
if (port && find_wind(port)) return port; /* this window is already open */
if (!port)
{
for (i=1; i<MAX_WIND; i++)
{
if (!find_wind(i))
{
port = i; /* a free port */
break;
}
}
}
wtyp = (sliders ? WI_WITHSLD : 0) | (titles ? WI_NOSLD : 0);
wind_calc(0, wtyp, 0, 0, curfont->inc_x*xsiz+2*X0,
curfont->inc_y*ysiz+2*Y0, &dummy, &dummy, &tmp_w, &tmp_h);
if (tmp_w>scr_w)
tmp_w = scr_w; /* full size <= screen size */
tmp_x = 10*(port-1);
if (tmp_h>scr_h)
tmp_h = scr_h;
tmp_y = scr_y+16*(port-1);
wdes = wind_create(wtyp, tmp_x, tmp_y, tmp_w,
tmp_h);
if (wdes < 0)
{
form_alert(1, "[1][Sorry, GEM has|no more windows|for us...][Ok]");
return 0;
}
wp = &w[wdes];
wp->wi_w = X0*2 + curfont->inc_x*xsiz;
wp->wi_h = Y0*2 + curfont->inc_y*ysiz;
wp->port = port;
if (!fast)
graf_growbox(0, 0, 20, 10, tmp_x, tmp_y, tmp_w, tmp_h);
wind_open(wdes, tmp_x, tmp_y, tmp_w, tmp_h);
wind_get(wdes, WF_WORKXYWH, &wp->x, &wp->y, &wp->w, &wp->h);
wp->fulled = 0;
wp->used = 1;
wp->x_off = 0;
wp->y_off = 0;
wp->px_off = 0;
wp->py_off = 0;
wp->m_off = wp->x & 15;
wp->cur_x = X0;
wp->cur_y = Y0;
wp->top_y = Y0;
wp->font = curfont;
wp->x_chrs = xsiz;
wp->y_chrs = ysiz;
wp->wi_mf.wpix = 2*X0 + xsiz*curfont->inc_x;
wp->wi_mf.hpix = 2*Y0 + ysiz*curfont->inc_y;
#ifdef KOPY
wp->wi_mf.wwords = ((wp->wi_mf.wpix>>5) +1) << 1;
#else
wp->wi_mf.wwords = (wp->wi_mf.wpix>>4) +1;
#endif
wp->wi_mf.ptr = getmem(((long)wp->wi_mf.hpix+wp->font->inc_y*MAXSCROLLED)
*wp->wi_mf.wwords*2);
wp->wi_mf.format = 0;
wp->wi_mf.planes = 1;
wp->ptr_status = LOG_NONE;
wp->wi_style = wtyp;
w_rename(wdes, name);
strcpy(wp->wi_fpath, ".\\*.*");
wp->top_age = 1;
for (cnt = 1; cnt < MAX_WIND; cnt++)
if (w[cnt].port != 0)
w[cnt].top_age++;
setvslide(wdes);
sethslide(wdes);
return wp->port;
}
/* w_closei removes a window but does not release its storage.
* This is used if the window contents must be saved for later use.
*/
w_closei(wdes)
{
int xx, yy, ww, hh;
register struct wi_str *wp = &w[wdes];
if (!wp->used) return;
if (wp->wi_lfd)
fclose(wp->wi_lfd);
wind_get(wdes, WF_CURRXYWH, &xx, &yy, &ww, &hh);
wind_close(wdes);
if (!fast)
graf_shrinkbox(0, 0, 20, 10, xx, yy, ww, hh);
wind_delete(wdes);
}
/* w_close removes a window. Most work is done by GEM, although w_close
* does some cleanup functions, too.
*/
w_close(wdes)
{
register struct wi_str *wp = &w[wdes];
if (!wp->used) return;
w_closei(wdes);
Mfree(wp->wi_mf.ptr);
bzero(wp, (long)sizeof (struct wi_str));
}
/* w_resize resizes an existing window.
*/
w_resize(wdes, xsiz, ysiz)
{
register struct wi_str *wp1 = &w[wdes];
struct wi_str *wp2;
struct wi_str ws;
static int c[8];
int port, wind, i;
if (!wp1->used) return;
ws = *wp1;
port = find_port(wdes);
w_closei(wdes);
bzero(wp1, (long)sizeof (struct wi_str));
port = w_open(port, "", xsiz, ysiz);
wind = find_wind(port);
wp2 = &w[wind];
c[0] = ws.m_off;
c[1] = ws.top_y + max(0, ws.wi_mf.hpix - wp2->wi_mf.hpix);
c[2] = c[0] + min(ws.wi_mf.wpix, wp2->wi_mf.wpix);
c[3] = c[1] + min(ws.wi_mf.hpix, wp2->wi_mf.hpix);
c[4] = wp2->m_off;
c[5] = wp2->top_y;
c[6] = c[4] + min(ws.wi_mf.wpix, wp2->wi_mf.wpix);
c[7] = c[5] + min(ws.wi_mf.hpix, wp2->wi_mf.hpix);
/* copy screen */
vro_cpyfm(handle, FM_COPY, c, &ws.wi_mf, &wp2->wi_mf);
/* copy parameters */
wp2->inverse = ws.inverse;
wp2->insmode = ws.insmode;
if (wp2->font != ws.font)
{
wp2->cur_x = X0;
wp2->cur_y = (wp2->y_chrs - 1) * wp2->font->inc_y + Y0;
}
else
{
wp2->cur_x = (wp2->x_chrs - 1) * wp2->font->inc_x + X0;
if (ws.cur_x < wp2->cur_x)
wp2->cur_x = ws.cur_x;
wp2->cur_y = max(0, ws.cur_y - c[1]) + Y0;
}
wp2->state = ws.state;
for (i=0; i<80; i++) wp2->nuname[i] = ws.nuname[i];
for (i=0; i<80; i++) wp2->wi_fpath[i] = ws.wi_fpath[i];
for (i=0; i<20; i++) wp2->wi_fname[i] = ws.wi_fname[i];
wp2->nuptr = ws.nuptr;
wp2->ptr_status = ws.ptr_status;
wp2->wi_lfd = ws.wi_lfd;
wp2->kerm_act = ws.kerm_act;
w_rename(wind, ws.name);
Mfree(ws.wi_mf.ptr);
return port;
}
/* w_rename changes the title bar of a window
*/
w_rename(wdes, name)
char *name;
{
register struct wi_str *wp = &w[wdes];
if (name)
strcpy(wp->name, name);
if (wp->wi_style & NAME)
{
sprintf(wp->dname, " %s%s %s ", (wp->ptr_status != LOG_NONE)? "\275": "",
wp->wi_lfd? "\237": "", wp->name);
wind_set(wdes, WF_NAME, wp->dname + (wp->dname[1] == ' '), 0, 0);
}
}
/* w_redraw redraws part of the screen from window contents.
* The coordinates are screen relative.
*/
w_redraw(wdes, logic, xx, yy, ww, hh)
{
static int c[8];
static GRECT t1, t2;
register struct wi_str *wp = &w[wdes];
if (xx+ww > scr_w)
ww = scr_w - xx;
if (yy+hh > scr_h+scr_y)
hh = scr_h+scr_y - yy;
t2.g_x = xx; t2.g_y = yy;
t2.g_w = ww; t2.g_h = hh;
t1.g_x = wp->x; t1.g_y = wp->y;
t1.g_w = wp->w; t1.g_h = wp->h;
if (!rc_intersect(&t2, &t1)) return; /* nothing to do... */
wind_update(TRUE);
wind_get(wdes, WF_FIRSTXYWH, &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h);
while (t1.g_w && t1.g_h)
{
if (rc_intersect(&t2, &t1))
{
if (mouse)
{
/* we have to do graphics, so switch the mouse off.
* mouse will be switched on again in main loop.
* this is ugly, but it improves speed a bit...
*/
mouse = 0;
graf_mouse(M_OFF, NULL);
}
#ifdef KCOPY
tfbmr(wp->wi_mf.ptr, t1.g_x - wp->x + wp->x_off + wp->m_off,
t1.g_y - wp->y + wp->y_off + wp->top_y - Y0, wp->wi_mf.wwords >> 1,
screen_mf.ptr, t1.g_x, t1.g_y, screen_mf.wwords >> 1,
t1.g_w, t1.g_h, logic);
#else
c[0] = t1.g_x - wp->x + wp->x_off + wp->m_off;
c[1] = t1.g_y - wp->y + wp->y_off + wp->top_y - Y0;
c[2] = c[0] + t1.g_w - 1;
c[3] = c[1] + t1.g_h - 1;
c[4] = t1.g_x;
c[5] = t1.g_y;
c[6] = c[4] + t1.g_w - 1;
c[7] = c[5] + t1.g_h - 1;
vro_cpyfm(handle, logic, c, &wp->wi_mf, &screen_mf);
#endif
}
wind_get(wdes, WF_NEXTXYWH, &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h);
}
if (!fast && !mouse)
{
mou